/* Filename: sleep.c
 * Description: 用户态木马病毒隐藏
 * Last modified: humble 20200322 17:05
 */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

static void usage(void);

int main(int argc, char **argv) {
    if(argc != 1){ fprintf(stderr, "argc !=1"); usage(); exit(1); }

    puts("begin");
    fflush(NULL);

    pid_t pid = fork();
    if(pid < 0){ perror("fork()"); exit(1); }
    else if(pid == 0){ // 子进程
        execl("/bin/sleep", "httpd", "100", NULL);
        // ps axf 显示shell->./sleep->httpd 100
        // 实际上是执行/bin/sleep 100的功能，但ps显示的却是argv[0]的名字，即httpd
        perror("execl()");
        exit(1);
    }

    wait(NULL);
    puts("end");
    return 0;
}

static void usage(void)
{
#define USAGE "Usage:\n\
  Helloworld\n"
    printf(USAGE);
}
